package com.hbnu.iostream;

import java.io.*;

/**
 * 需求：通过转换流InputStreamReader读取指定文件中的内容
 *
 * @author kittychen
 * @since 2025-10-13 17:00
 */
public class InputStreamReaderDemo {
    public static void main(String[] args) {
        String path = "C:" + File.separator + "Users" + File.separator + "Administrator"
                + File.separator + "Desktop" + File.separator + "kittychen"
                + File.separator + "class2311" + File.separator + "2311.txt";
        File file = new File(path);

        InputStreamReader inputStreamReader = null;

        try {
            inputStreamReader = new InputStreamReader(new FileInputStream(file));
            char[] buff = new char[1024];
            int len = 0;
            int temp;
            while ((temp = inputStreamReader.read()) != -1) {
                buff[len++] = (char) temp;
            }

            System.out.println(new String(buff, 0, len));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStreamReader != null) {
                    inputStreamReader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
